# -*- coding: UTF-8 -*-

from application.config.redis import connect_redis


def get_redis_info(db_num):
    redis_db = connect_redis(db_num)
    info = redis_db.info()
    return info


def calculate_redis_size(db_num):
    info = get_redis_info(db_num)
    used_memory = int(info['used_memory'])
    used_memory_human = info['used_memory_human']
    return used_memory, used_memory_human


# 示例用法
db_num = 7  # Redis数据库编号
used_memory, used_memory_human = calculate_redis_size(db_num)
print(f"Redis占用空间大小：{used_memory} bytes ({used_memory_human})")
